package com.mimc.controller.admin;

import com.jfinal.aop.Inject;
import com.jfinal.core.paragetter.Para;
import com.jfinal.plugin.activerecord.Page;
import com.mimc.core.model.SysDictType;
import com.mimc.core.service.SysDictTypeService;
import com.mimc.framework.domain.AjaxResult;
import com.mimc.framework.jwt.AdminTokenUtils;
import io.jboot.db.model.Columns;
import io.jboot.web.controller.JbootController;
import io.jboot.web.controller.annotation.RequestMapping;

import java.util.Date;

@RequestMapping("/admin/sys/dict/type")
public class SysDictTypeController extends JbootController {
    @Inject
    private SysDictTypeService sysDictTypeService;
    public AjaxResult lists(){
        Integer page=getInt("page",1);
        Integer pageSize=getInt("pageSize",15);
        Page<SysDictType> list=sysDictTypeService.paginateByColumns(page,pageSize, Columns.create(),"create_time desc");
        return AjaxResult.success("成功",list);
    }

    public AjaxResult add(@Para("") SysDictType sysDictType){
        sysDictType.setCreateBy(AdminTokenUtils.getUserName());
        sysDictType.setCreateTime(new Date());
        sysDictTypeService.save(sysDictType);
        return AjaxResult.success("添加成功");
    }

    public AjaxResult update(@Para("") SysDictType sysDictType){
        sysDictType.setUpdateBy(AdminTokenUtils.getUserName());
        sysDictType.setUpdateTime(new Date());
        sysDictTypeService.update(sysDictType);
        return AjaxResult.success("更新成功");
    }

    public AjaxResult delete(Long dictId){
        SysDictType sysDictType=sysDictTypeService.findById(dictId);
        sysDictTypeService.delete(sysDictType);
        return AjaxResult.success("删除成功");
    }
}
